package com.lwt.spock

import com.lwt.spock.dao.MoneyDao
import com.lwt.spock.dao.UserDao
import com.lwt.spock.pojo.dto.UserDTO
import com.lwt.spock.service.UserService
import spock.lang.Specification

/**
 * @author lwt*
 * @Description
 * @date  2021/8/15 16:53
 * @version 1.0
 */
class UserServiceTest extends Specification{
    def userService = new UserService()
    def userDao = Mock(UserDao)

    // 每个测试运行前的启动方法
    void setup(){
        userService.userDao = userDao
    }
    def "GetUserById"() {
        given : "设置请求参数"
        def user1 = new UserDTO(id:1,name: "张三",province: "上海")
        def user2 = new UserDTO(id:2,name: "李四",province: "江苏")
        and:"mock掉接口返回的用户信息"
        userDao.getUserInfoList() >> [user1,user2]

        when: "调用获取用户信息方法"
        def response  = userService.getUserById(1)

        then : "验证返回结果是否符合预期值"
        with(response){
            name == "张三"
            abbreviation == "沪"
            postCode == 200000
        }
    }
}
